﻿using System;
using System.Collections.Generic;
using System.Text;

namespace tc58News
{
	public class Channel
	{
		Queue<HtmlSource> TaskQueue = new Queue<HtmlSource>();
		public int bufferCount = 0;
		object lockObj = new object();
		public HtmlSource GetBuffer()
		{

			lock (lockObj)
			{
				//判断如果缓冲区内无内容,则Consumer进入wait状态,并且释放对象锁
				if (bufferCount <= 0)
				{
					//OutPubLog("缓冲区无数据..等待获取!");
					return null;
					// Monitor.Wait(this);
				}

				bufferCount--;
				//OutPubLog("返回一个任务 剩余" + bufferCount.ToString());
				return TaskQueue.Dequeue();

			}

		}

		public void SetBuffer(HtmlSource source)
		{
			lock (lockObj)
			{
				bufferCount++;
				//OutPubLog("添加一个队列,剩余:" + bufferCount.ToString());
				TaskQueue.Enqueue(source);

			}
		}

	}
}
